// Fp_BPA.cpp: implementation of the CFp_BPA class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "../../Include/Swi/Fp_BPA.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CFp_BPA::CFp_BPA()
{
	m_chType = 'F';
	m_chSubType = '+';
	m_chChangeCode = ' ';

	m_dVAMax = 0;
	m_dVAMin = 0;
	m_dKb = 0;
	m_dT5 = 0;
	m_dKe = 0;
	m_dTe = 0;
	m_dSe1 = 0;
	m_dSe2 = 0;
	m_dVRMax = 0;
	m_dVRMin = 0;
	m_dKc = 0;
	m_dKd = 0;
	m_dKl1 = 0;
	m_dVl1r = 0;
	m_dEFDMax = 0;

	m_strCardType[0] = 'F';
	m_strCardType[1] = '1';
}

CFp_BPA::CFp_BPA(CFp_BPA &fpBPA):CUnit_BPA(fpBPA)
{
	m_dVAMax = fpBPA.m_dVAMax;
	m_dVAMin = fpBPA.m_dVAMin;
	m_dKb = fpBPA.m_dKb;
	m_dT5 = fpBPA.m_dT5;
	m_dKe = fpBPA.m_dKe;
	m_dTe = fpBPA.m_dTe;
	m_dSe1 = fpBPA.m_dSe1;
	m_dSe2 = fpBPA.m_dSe2;
	m_dVRMax = fpBPA.m_dVRMax;
	m_dVRMin = fpBPA.m_dVRMin;
	m_dKc = fpBPA.m_dKc;
	m_dKd = fpBPA.m_dKd;
	m_dKl1 = fpBPA.m_dKl1;
	m_dVl1r = fpBPA.m_dVl1r;
	m_dEFDMax = fpBPA.m_dEFDMax;
}

CFp_BPA::~CFp_BPA()
{

}

bool CFp_BPA::FillEx(char *buffer)
{
	bool bResult = CUnit_BPA::FillEx(buffer);

	if (!bResult)
	{
		printf("Error in (CFp_BPA: FillEx): no basic information!\n");
		return false;
	}

	if (strlen(buffer)<17)
	{
		printf("Error in (CFp_BPA: FillEx): Fp has no parameter!\n");
		return false;
	}

	m_dVAMax = StrToDouble(&buffer[16],5,3);
	if(EndOfSec(&buffer[16],5))
		return true;

	m_dVAMin = StrToDouble(&buffer[21],5,3);
	if(EndOfSec(&buffer[21],5))
		return true;

	m_dKb = StrToDouble(&buffer[26],4,2);
	if(EndOfSec(&buffer[26],4))
		return true;

	m_dT5 = StrToDouble(&buffer[30],4,2);
	if(EndOfSec(&buffer[30],4))
		return true;

	m_dKe = StrToDouble(&buffer[34],4,2);
	if(EndOfSec(&buffer[34],4))
		return true;
	
	m_dTe = StrToDouble(&buffer[38],4,2);
	if(EndOfSec(&buffer[38],4))
		return true;
	
	m_dSe1 = StrToDouble(&buffer[42],5,4);
	if(EndOfSec(&buffer[42],5))
		return true;
	
	m_dSe2 = StrToDouble(&buffer[47],5,4);
	if(EndOfSec(&buffer[47],5))
		return true;
	
	m_dVRMax = StrToDouble(&buffer[52],4,2);
	if(EndOfSec(&buffer[52],4))
		return true;
	
	m_dVRMin = StrToDouble(&buffer[56],4,2);
	if(EndOfSec(&buffer[56],4))
		return true;

	m_dKc = StrToDouble(&buffer[60],4,2);
	if(EndOfSec(&buffer[60],4))
		return true;

	m_dKd = StrToDouble(&buffer[64],4,2);
	if(EndOfSec(&buffer[64],4))
		return true;

	m_dKl1 = StrToDouble(&buffer[68],4,2);
	if(EndOfSec(&buffer[68],4))
		return true;

	m_dVl1r = StrToDouble(&buffer[72],4,2);
	if(EndOfSec(&buffer[72],4))
		return true;

	m_dEFDMax = StrToDouble(&buffer[76],4,2);
	if(EndOfSec(&buffer[76],4))
		return true;

	return true;
}

bool CFp_BPA::UpdateEx(char *buffer)
{
	bool bResult = CUnit_BPA::UpdateEx(buffer);

	if (!bResult)
	{
		printf("Error in (CFp_BPA: UpdateEx): impossible!\n");
		return false;
	}

	DoubleToStr(m_dVAMax,&buffer[16],5,3);
	DoubleToStr(m_dVAMin,&buffer[21],5,3);
	DoubleToStr(m_dKb,&buffer[26],4,2);
	DoubleToStr(m_dT5,&buffer[30],4,2);
	DoubleToStr(m_dKe,&buffer[34],4,2);
	DoubleToStr(m_dTe,&buffer[38],4,2);
	DoubleToStr(m_dSe1,&buffer[42],5,4);
	DoubleToStr(m_dSe2,&buffer[47],5,4);
	DoubleToStr(m_dVRMax,&buffer[52],4,2);
	DoubleToStr(m_dVRMin,&buffer[56],4,2);
	DoubleToStr(m_dKc,&buffer[60],4,2);
	DoubleToStr(m_dKd,&buffer[64],4,2);
	DoubleToStr(m_dKl1,&buffer[68],4,2);
	DoubleToStr(m_dVl1r,&buffer[72],4,2);
	DoubleToStr(m_dEFDMax,&buffer[76],4,2);

	return true;
}